package com.MRYIN.controller;

import com.MRYIN.mapper.PaymentsMapper;
import com.MRYIN.pojo.Payments;
import com.MRYIN.service.PaymentsService;
import com.MRYIN.util.DataGridView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @program: SHYC_03
 * @description: 款项管理的控制器
 * @author: Mr.YIN
 * @create: 2021-02-25 13:51
 **/
@Controller
@RequestMapping("/Payments")
public class PaymentsController {

    private static final Logger logger = LoggerFactory.getLogger(PaymentsController.class);

    @Autowired
    private PaymentsService paymentsService;

    @RequestMapping("/toPaymentsList")
    public String toPaymentsList() {
        logger.info("跳转到款项管理tab");
        return "Payments/PaymentsList";
    }

    @RequestMapping("/PaymentsTableList")
    @ResponseBody
    public DataGridView paymentsTableList() {
        List<Payments> payments = paymentsService.queryAllPayments();
        logger.info("查询所有款项，显示在layui-table中===>");
        return new DataGridView(0, "查询成功", (long) payments.size(), payments);
    }

    @RequestMapping("/PaymentsTopForm/{params}")
    @ResponseBody
    public DataGridView paymentsTopForm(@PathVariable("params") String payments){
        String[] split = payments.split("&");
        String search_3 = split[split.length-2];
        String search_4 = split[split.length-1];

        String[] search_3_split = search_3.split("=");
        //款项编号
        String PAY_CODE = search_3_split[search_3_split.length-1];
        //项目号
        String PAY_PRJCODE = "";
        String[] search_4_split = search_4.split("=");
        if(search_4_split.length == 1){
            PAY_PRJCODE = "";
        }else{
            PAY_PRJCODE = search_4_split[search_4_split.length-1];
        }
        System.out.println(PAY_CODE);
        System.out.println(PAY_PRJCODE);
        List<Payments> paymentslist = paymentsService.queryAllPaymentsByPAY_CODEOrPAY_PRJCODE(PAY_CODE, PAY_PRJCODE);
        return new DataGridView(0,"查询成功", (long) paymentslist.size(),paymentslist);
    }
}
